package com.yingside.collection.book;

import java.util.ArrayList;
import java.util.List;

public class BookManager {
    private List<Book> list = new ArrayList<>();

    public void add(Book b){
        list.add(b);
    }

    public Book[] filter(BookFilter filter){
        List<Book> newBooks = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Book book = list.get(i);
            if(filter.filter(book.getId(),book.getBookName(),book.getAuthor(),book.getPrice())){
                newBooks.add(list.get(i));
            }
        }

        return newBooks.toArray(new Book[newBooks.size()]);
    }
}
